<script>
function checkAll(field){ 
    for (i = 0; i < field.length; i++)
    field[i].checked = true ;
}
function uncheckAll(field){
    for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}
function deleted(){ 
   var distribute = new Array();
   var i=0;
   var getId = jQuery('input[name=id]:checked');
   jQuery(getId).each(function(k,y){
        distribute[i] = y.id;
        i++;
    });
    jQuery.ajax({
       url:'category/deleted',
       data:'Category_code='+distribute,
       type:'post',
       success: function(){
          
       }
    })
}
function deletedOnce(id){ 
  
    jQuery.ajax({
       url:'category/deleted',
       data:'Category_code='+id,
       type:'post',
       success: function(){
          
       }
    })
}
</script>
<form id="categories" name="categories">
<fieldset>
    <legend>Categories</legend>
    <div class="container-button">
    <a href="catalog/form" class="button-form">Add</a>
    <a href="catalog/form" class="button-form" onclick="deleted();return false;">Trash</a>
    </div>
<table>
    <tr>
      <th></th><th>No.</th><th>Product Name</th><th>product info</th><th>prices</th> <th>category name</th><th>Image</th><th>Action</th>
    </tr>
<?php 
$i=1;
foreach($this->data as $data):?>
    <tr><td><input type="checkbox" name="id" id="<?php echo $data['product_code']?>" /></td>
        <td><?php echo $i++;?></td><td><?php echo $data['product_name']; ?> </td><td><?php echo $data['product_info']?></td> 
        <td><?php echo $data['purchase_cost'];?></td><td><?php echo $data['category_name']; ?></td> 
        <td><img src="<?php echo $this->base_url."../../catalog/".$data['image'];?>"  width="100" height="100"/></td>
        <td><a href="category/form/<?php echo $data['product_code']?>"> Edit</a> || <a href="#" id="<?php echo $data['product_code']?>" onclick="deletedOnce(this.id);return false;"> Delete</a></td>
    </tr>
    <?php endforeach;?>
</table>
    <a href="#" onclick="checkAll(categories.id);return false;">Check All</a>
      <a href="#" onclick="uncheckAll(categories.id);return false;">UnCheck All</a>
</fieldset>
</form>